//
//  UIView+IsVisibleOrNot.m
//  百思不得姐
//
//  Created by 胥鸿儒 on 16/6/20.
//  Copyright © 2016年 xuhongru. All rights reserved.
//

#import "UIView+IsVisibleOrNot.h"

@implementation UIView (IsVisibleOrNot)

//判断一个控件是否在可见范围之内
- (BOOL)isVisible
{
    //转换坐标系
    CGRect keyWindowRect = [self.superview convertRect:self.frame toView:XHRKeyWindow];
    
    //判断2个矩形框是否交界
    BOOL rectIntersectsRect = CGRectIntersectsRect(keyWindowRect, XHRScreenBounds);
    //该控件可见的条件
    if (self.hidden || self.alpha <= 0.01) return NO;
    
    //判断是不是在主窗口上
    else if(rectIntersectsRect && self.window == XHRKeyWindow) return YES;
    else return  NO;
}

@end
